package com.tengju.data.infrastructure.repository;

import com.tengju.data.domain.model.user.ReportDealerNewUserInfo;
import com.tengju.data.domain.model.user.ReportDealerNewUserRepository;
import com.tengju.data.infrastructure.persistence.mybatis.dataobject.ReportDealerNewUserDO;
import com.tengju.data.infrastructure.persistence.mybatis.mapper.data.custom.ReportDealerNewUserMapper;
import com.tengju.data.infrastructure.repository.convert.ReportDealerNewUserConvert;
import com.tengju.user.domain.model.user.UserIdCode;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Repository
public class ReportDealerNewUserRepositoryImpl implements ReportDealerNewUserRepository {

    @Resource
    ReportDealerNewUserMapper reportDealerNewUserMapper;


    /**
     * 社群新增
     */
    @Override
    public List<ReportDealerNewUserInfo> selectByIdCodeAndMonth(UserIdCode idCode, Integer month) {
        List<ReportDealerNewUserDO> newUserDOList =
                reportDealerNewUserMapper.selectByIdCodeAndMonth(idCode.getValue(),month);
        if (CollectionUtils.isEmpty(newUserDOList)) {
            return Collections.emptyList();
        }
        return newUserDOList.stream()
                .map(ReportDealerNewUserConvert::toModel)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
